#!/bin/bash

if [ $# -ne 1 ]; then
	echo "usage: appattach diskimage"
	exit 1
fi

diskimage=$1
appfs=$(dirname $0)/appfs

if [ -e $appfs ]; then
	echo -n "appattach: placing appfs bootstrap into $diskimage... "
else
	echo "appattach: error: could not locate appfs at $appfs."
	exit 1
fi

dd if=$appfs of=$diskimage count=1 bs=1M conv=sync,notrunc >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
	echo "failed (dd)!"
	exit $?
fi
chmod u+x $diskimage >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
        echo "failed (chmod)!"
        exit $?
fi

echo "done."
exit 0
